#include <iostream>
#include <vector>
using namespace std;

int maxProfit(vector<int> &prices) {
    // Start typing your C/C++ solution below
    // DO NOT write int main() function
    if(prices.size() < 2){
        return 0;
    }
    int maxP = 0;
    int minPrice = prices[0];
    int maxPrice = prices[0];
    for(int i=1; i<prices.size(); ++i){
        if(prices[i]<minPrice){
            // rest bound
            minPrice = prices[i];
            maxPrice = prices[i];
        }
        else if(prices[i]>maxPrice){
            // hope
            maxPrice = prices[i];
            int profit = maxPrice - minPrice;
            if(profit > maxP){
                maxP = profit;
            }
        }
    }
    return maxP;

}

int main(){
    return 0;
}